package com.easyidea.its.domain.service.department.impl;

import java.util.Collection;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.criterion.Restrictions;

import com.easyidea.its.domain.model.system.Department;
import com.easyidea.its.domain.model.system.PassPort;
import com.easyidea.its.domain.repository.department.PassPortRepository;
import com.easyidea.its.domain.service.base.impl.BaseServiceImpl;
import com.easyidea.its.domain.service.department.PassPortService;

public class PassPortServiceImpl extends BaseServiceImpl<PassPort> implements PassPortService {

	private PassPortRepository passPortRepository;
	
	@Override
	public PassPortRepository getBaseRepository() {
		return passPortRepository;
	}	
	
	public List<PassPort> getPassPorts(PassPort passport, int startAtIndex, int pageSize) {
		// TODO Auto-generated method stub
		return passPortRepository.getPassPorts(passport, startAtIndex, pageSize);
	}

	public int getPassPortsCount(PassPort passport) {
		// TODO Auto-generated method stub
		return passPortRepository.getPassPortsCount(passport);
	}
	 public void removePassPortById(Integer id) {
		 Query q = this.getSessionFactory().getCurrentSession().createQuery(
					"delete from " + PassPort.class.getName() + " where id = "
							+ id);
			q.executeUpdate();			
	}

	public boolean hasSamePassPortName(String passPortName, Integer id) {
		// TODO Auto-generated method stub
		return passPortRepository.hasSamePassPortName(passPortName, id);
	}

	public void setPassPortRepository(PassPortRepository passPortRepository) {
		this.passPortRepository = passPortRepository;
	}
	@SuppressWarnings("unchecked")
	public Collection<PassPort> getAllPassPortByDeptId(Integer deptId) {
		Criteria ca = this.passPortRepository.createUndeleteCriteria();
		ca.add(Restrictions.eq("department.id", deptId));
		return ca.list();
	}
	public  PassPort getPassPortByPassPortName(String passPortName) {
		Criteria ca = this.getBaseRepository().createUndeleteCriteria();
		ca.add(Restrictions.eq("passPortName", passPortName));
		return (PassPort) ca.uniqueResult();
	}
	@SuppressWarnings("unchecked")
	public Collection<PassPort> getAllPassPorts() {
		Criteria ca = this.passPortRepository.createUndeleteCriteria();
		return ca.list();
	}
	

}
